package net.vinote.smart.platform.service.handler;

import java.util.regex.Pattern;

import net.vinote.smart.platform.module.database.bo.BizObject;
import net.vinote.smart.platform.service.dw.handler.CommonHandler;
import net.vinote.smart.platform.service.dw.handler.HandlerPerimissionAnnotation;
import net.vinote.smart.platform.service.util.Permission;
import net.vinote.smart.platform.service.util.Permission.PermissionEnum;

/**
 * @author Seer
 * @version SystemParamHandler.java, v 0.1 2015年3月5日 下午1:29:21 Seer Exp.
 */
@HandlerPerimissionAnnotation(
		insert = @Permission(PermissionEnum.SMART_SYSTEM_PARAM_INSERT),
		update = @Permission(PermissionEnum.SMART_SYSTEM_PARAM_UPDATE),
		delete = @Permission(PermissionEnum.SMART_SYSTEM_PARAM_DELETE),
		query = @Permission(PermissionEnum.SMART_SYSTEM_PARAM_QUERY))
public class SystemParamHandler extends CommonHandler {

	@Override
	public void initDisplayForEdit(BizObject bo) {
		setReadOnly("RULE,paramName", true);
	}

	@Override
	protected boolean validityCheck(BizObject bo, boolean isInsert) {
		boolean isPass = true;
		// 校验系统参数值是否符合正则规则
		String reg = bo.getAttribute("rule");
		String paramValue = bo.getAttribute("paramValue");
		Pattern pattern = Pattern.compile(reg);
		if (!pattern.matcher(paramValue).matches()) {
			error = "参数值:" + paramValue + " 不符合正则:" + reg;
			isPass = false;
		}
		return isPass;
	}

}
